#!/bin/zsh -f

# For tramp et al., don't do anything fancy.
if [[ "$TERM" == "dumb"  ]]
then
  unsetopt zle
  unsetopt prompt_cr
  unsetopt prompt_subst
  unfunction precmd
  unfunction preexec
  PS1='$ '
  return
fi

source ~/.zsh_functions

# Reattach or start a new Tmux.
# This function name is short because I want to call it this way
# interactively.
t

# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh

# Set my terminal if I'm not in tmux.
[[ "$TMUX" == "" ]] && TERM=xterm-256color

# Disable autosetting terminal title.
DISABLE_AUTO_TITLE="true"

# Disable command autocorrection.
DISABLE_CORRECTION="true"

# Display red dots while waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Disable marking untracked files under VCS as dirty. This makes repository
# status check for large repositories much, much faster.
DISABLE_UNTRACKED_FILES_DIRTY="true"

# Load these oh-my-zsh plugins.
plugins=(git colorize themes virtualenv)

# If virtualenvwrapper is installed, also activate that plugin and make sure
# things are set up to work properly.
#
# If it is NOT installed, you should `brew install
# pyenv-virtualenvwrapper` and then reopen your shell a couple of
# times for these checks to pass and set things up.
vnw_script="/usr/local/bin/virtualenvwrapper.sh"
if [[ -e "$vnw_script" ]]; then
  source "$vnw_script"
fi

vew_on_path=$(type virtualenvwrapper >/dev/null; echo $?)
if [[ "$vew_on_path" -eq 0 || -e "$vnw_script" ]]; then
  if [[ ! -d "$HOME/.virtualenvs" ]]; then
    mkdir "$HOME/.virtualenvs"
  fi
  export WORKON_HOME="$HOME/.virtualenvs"
  plugins=($plugins virtualenvwrapper)
fi

# Configure zsh options #######################################################
setopt autolist       # Display completion candidates immediately.
setopt cdablevars     # When an argument should be a dir but is not one,
                      # expand it as if it started with ~ (see below).
setopt autonamedirs   # Any parameter that is set to an abosolute directory
                      # name automatically becomes a name for that directory
                      # in the form ~param.
setopt histignoredups # Do not record a command in the history if it is a
                      # duplicate of the previous one.
setopt listtypes      # When listing files that are possible completions,
                      # indicate their types with a trailing character.
setopt nolistbeep     # No bell on ambiguous completion!!

# I like my slow locomotive.
unalias sl > /dev/null 2>&1

source $ZSH/oh-my-zsh.sh
source $HOME/.zsh_prompt

# Use VI mode.
bindkey -v
bindkey '^R' history-incremental-search-backward

# Adjust widget behaviors. ####################################################
# While selecting from menu completion, pressing enter accepts the selection
# and executes the command.
bindkey -M menuselect '^M' .accept-line

function nicediff {
  diff -W `tput cols` -y "$@" | colordiff | less
}

### Aliases.
## Tmux:
alias ta="tmux attach"
alias tad="tmux attach -d"
alias tl="tmux ls"
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
alias ssh='ssh -A'
alias cpr="rsync -aP"

command -v xdg-open >/dev/null 2>&1 && alias open="xdg-open"

## Emacs:
export EDITOR="$HOME/bin/editor"
export VISUAL="$HOME/bin/editor"
alias e="$EDITOR"
export ALTERNATE_EDITOR=""

## Heuristic to compute location because I am lazy.
if [[ `whoami` == "airborne" ]]; then
  export MY_LOCATION="home"
else
  export MY_LOCATION="work"
fi

if [ -f "$HOME/.zshrc_$MY_LOCATION" ]; then
  source "$HOME/.zshrc_$MY_LOCATION"
fi

# OS X things.
if [[ `uname` == "Darwin" ]]; then
  function top() {
    if [ $# -eq 0 ]; then
      /usr/bin/top -o cpu
    else
      /usr/bin/top "$@"
    fi
  }

  # Always use:
  #   l: List in long format
  #   h: Sizes in human-readable form
  #   F: Dir, symlink, executable, etc., symbols
  #   G: Colorize!
  alias l="ls -lhFG"
  alias la="ls -lhFGA"   # All files
  alias ltr="ls -lhFGtr" # By time, reverse
  alias lsr="ls -lhFGSr" # By size, reverse
else
  # Non-OS X things.
  alias l="ls -lhF --group-directories-first --color=always"
fi

if [[ "$PATH" == *System32* ]]; then
  cd
  umask 022

  eval $(/c/Users/Aaron/scoop/apps/ssh-agent-wsl/current/ssh-agent-wsl -r)
  export DOCKER_HOST=tcp://localhost:2375
fi
# vim: set et ts=2 sw=2 tw=79 cc=+1 :
